<template>
	<view style='padding:15px;'>
		<u--form :model="formData" ref="form1">
			<u-form-item label="机构" prop="depCodeParam" @click="showSelect = true;aNum=1" labelWidth='150'>
				<u--input v-model="formData.depCodeParam" placeholder="请选择区划" readonly @change='changeInput'>
				</u--input>
			</u-form-item>
			<u-form-item label="评估周期" prop="executionDate" labelWidth='150' @click="showDate = true;">
				<uni-datetime-picker :show="showDate" @close='showDate = false;' v-model="formData.executionDate"
					type="date" />
			</u-form-item>
		</u--form>
		<!-- 区划-->
		<qianziyuSelect :show="showSelect" type="radio" :dataLists="columns" placeholder="请搜索"
			@cancel="showSelect=false" @submit="confirmSelect" @search='search'></qianziyuSelect>
		<u-button style='margin:15px auto;width:80%;' type="primary" size="large" @click="btnSearch()">查询</u-button>
		<u-button style='margin:15px auto;width:80%;' type="primary" size="large" @click="btnReset()">重置</u-button>
	</view>
</template>
<script>
	import qianziyuSelect from '@/components/qianziyu-select/qianziyu-select.vue'
	export default {
		components: {
			qianziyuSelect
		},
		data() {
			return {
				formSearch: {
					depCodeParam: "",
					coName: "",

				},
				formData: {
					depCodeParam: "",
					coName: "",
				},
				columns: [],
				showSelect: false,
				showDate: false,
				options: {},
				keyList: [], //机构

			}
		},
		onLoad(option) {
			this.options = option
		},
		mounted() {
			this.$api.getDeptTreeById(this.$store.state.userInfo.dept_id).then(res => {
				res.data.data.map(item => {
					this.columns.push({
						id: item.value,
						name: item.title
					})
					// 备用
					this.keyList.push({
						id: item.value,
						name: item.title
					})
				})
			})
		},
		methods: {
			// 查询
			btnSearch() {
				this.formSearch.taskBeginTime = this.formData.executionDate[0]
				this.formSearch.taskEndTime = this.formData.executionDate[1]
				const searchList = {
					...this.options,
					...this.formSearch
				}
				this.$goBack('./checkInformation?direction=2&formSearch=' + encodeURIComponent(JSON.stringify(searchList)),
					5);
			},


			// 机构确定
			confirmSelect(e) {
				if (this.aNum == 1) {
					this.formData.depCodeParam = e.name
					this.formSearch.depCodeParam = e.id
				}
				this.showSelect = false
			},

			// 搜索查询
			search(keyword) {
				const aArr = ['columns']
				let arrList = []
				if (keyword == '') {
					if (this.aNum == 1) {
						this.columns = this.keyList
					}
				} else {
					this[aArr[this.aNum - 1]].forEach(item => {
						if (item.name.indexOf(keyword) != -1) {
							arrList.push(item)
						}
					})
					this[aArr[this.aNum - 1]] = arrList
				}

			},


			// 重置
			btnReset() {
				this.$refs.form1.resetFields()
			}


		}
	}
</script>

<style lang="scss" scoped>
</style>
